package com.heart.admin.controller;

import com.heart.common.constant.AppCode;
import com.heart.common.constant.AppConstant;
import com.heart.dao.dto.RequestResult;
import com.heart.dao.entity.Answer;
import com.heart.dao.entity.AnswerMain;
import com.heart.service.AnswerMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/answer")
public class AnswerController {
    @Autowired
    private AnswerMainService answerMainService;

    @PostMapping("/saveAnswer")
    public RequestResult saveAnswer(HttpServletRequest request, HttpServletResponse response,@RequestBody AnswerMain answerMain){
        return new RequestResult(AppCode.SUCCESS,answerMainService.saveAnswer(request,response,answerMain), AppConstant.SUCCESS);
    }
    @PostMapping("/deleteAnswer")
    public RequestResult deleteAnswer(String detailId){
        return new RequestResult(AppCode.SUCCESS,answerMainService.deleteAnswer(detailId), AppConstant.SUCCESS);
    }

    @PostMapping("/getAnswerMainListByQuestionId")
    public RequestResult getAnswerMainListByQuestionId(@RequestBody Map<String,String> map){
        return new RequestResult(AppCode.SUCCESS,answerMainService.getAnswerMainListByQuestionId(map.get("questionId")), AppConstant.SUCCESS);
    }
 @PostMapping("/getAnswerListByAnswerMainId")
    public RequestResult getAnswerListByAnswerMainId(@RequestBody Map<String,String> map){

     List<Answer> ansers = answerMainService.getAnswerListByAnswerMainId(map.get("mainId"));
     Map<String,Object> result = new HashMap<>();
     result.put("list", ansers);
     return new RequestResult(AppCode.SUCCESS,result, AppConstant.SUCCESS);
    }


}
